/*
 * Larento Flash Message Plugin
 * http://axcoto.info/
 *
 * Copyright (c) 2009 Vincent Nguyen <kureikain@gmail.com>
 * Licensed under the GPL.
 * 
 */

( function($) {
	$.fn.larento = function(options) {
		var defaults = {
			msg : 'Flash Message Axcoto',
			timeout : 2,
			type : 'specify'
		};
		
		options = $.extend(defaults, options);
		var elementId = (Math.random()) + '';
		elementId = "larento" + elementId.replace('.', '');
		
		options.msg = "<div class='AxcotoFlashMessage' id=\"" + elementId + "\">" + options.msg + "</div>"; 
		console.log(options);
		
		var make = function (obj, message, time) {
			switch (options.type) {
				case 'inside':
					var cacheHtml = obj.html();
					obj.html(message);
					console.log(obj);
					var fn = function () {
						obj.html(cacheHtml).fadeIn('slow');						
					}
					break;
				case 'append':
					$(options.msg).appendTo(obj).fadeIn('slow');
					var fn = function () {
						console.log(obj);
						$("#" + elementId).fadeOut('slow').remove();
						console.log($("#" + elementId));
					}
					break;
				case 'prepend':
					$(options.msg).prenpendTo(obj).fadeIn('slow');
					var fn = function () {
						console.log(obj);
						$("#" + elementId).fadeOut('slow').remove();
						console.log($("#" + elementId));
					}
					break;
				default:
					obj.html(message).fadeIn('slow');
					var fn = function () {
						obj.fadeOut('slow');
					}
			}			
			setTimeout(fn, options.timeout);
		};
		
		return this.each( function() {			
			obj = $(this);
			make(obj, options.msg, options.timeout);          
		});
	};
})(jQuery);